<?php 
namespace App\Services;

use Session;
use App\Facades\Infra\WeChatManage;

class WeightService{
	public function getHegithInSession($id){

		if(Session::has('user.height')){
			return Session::get('user.height');
		}

		// dd($this->getUser());

		Session::put('user.height',$this->getUser($id)->wechatUserInfo->height);

		return Session::get('user.height');
	}

	private function getUser($id){

		$conditions['id'] = $id;

		$wechatUser = WeChatManage::getUserInfoTwo($conditions)->first();

		return $wechatUser;
	}

	public function countBmi($weight,$height){
		$meterHeight = $height/100;

		$bmi = $weight/($meterHeight*$meterHeight);

		return round($bmi,1);
	}
}